package com.github.data_manage.dao

import com.github.data_manage.domain.po.Company
import com.github.data_manage.domain.po.CompanyShareholder
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

/**
 *@author CHN
 *@since 2024-08-07 22:07
 */
interface CompanyShareholderDao : BaseDao<CompanyShareholder> {

    fun removeAllByCompanyIdEquals(companyId: Int)

    fun findAllByCompanyIdEquals(companyId: Int): List<CompanyShareholder>

    @Modifying
    @Query("update CompanyShareholder set name = :personName where personId = :personId")
    fun updatePersonName(@Param("personId") personId: Int, @Param("personName") personName: String)

    @Modifying
    @Query("update CompanyShareholder set companyId = :mainCompanyId where companyId = :minorCompanyId")
    fun mergeCompany(@Param("mainCompanyId") mainCompanyId: Int, @Param("minorCompanyId") minorCompanyId: Int)
}
